package cn.itcast.blog.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

import cn.itcast.blog.Utils.ServiceProxyUtils;
import cn.itcast.blog.domain.AjaxResponse;
import cn.itcast.blog.domain.Post;
import cn.itcast.blog.service.CategoryService;
import cn.itcast.blog.service.PostService;
@WebServlet(urlPatterns= {
		"/post/find"
})
public class PostServlet extends BaseServlet{
	
	PostService postService = ServiceProxyUtils.cretaeProxy(new PostService());
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req,resp);
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		super.doGet(req, resp);
	}
	
	//增
	public void add(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
	}
	
	//删
	public void delete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
	}
	
	//改
	public void update(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
	}
	
	//查
	public void find(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		int page = Integer.valueOf(req.getParameter("page"));
		
		int limit = Integer.valueOf(req.getParameter("limit"));
		
		AjaxResponse<Post> findPage = postService.findPage(page, limit);
		
		String string = JSON.toJSONString(findPage);
		
		resp.setContentType("application/json;charset=utf-8");
		resp.getWriter().write(string);
	}
}
